package network.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class TcpClient {
    private final static int PORT = 9999;
    private static final String HOSTNAME = "127.0.0.1";

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(HOSTNAME ,PORT);
        OutputStream out=socket.getOutputStream();
        out.write("hello server".getBytes());
        out.flush();
        //告诉服务器端我写完了
        socket.shutdownOutput();

        byte[] bytes = new byte[1024];
        //等待服务器端响应
        while (socket.getInputStream().read(bytes) != -1) {
            System.out.println("服务器响应："+new String(bytes));
        }
        socket.close();
    }
}
